package p8;

/**
 * @author krystal
 * @date 2022/11/12 13:33
 */
class Animal{
    public String name;

    public Animal(String name) {
        this.name = name;
    }

    public void eat(){
        System.out.println(name+"正在吃饭");
    }
}

interface IRun{
    void run();
}

interface ISwim{
    void swim();
}

class Dog extends Animal implements IRun,ISwim{
    public Dog(String name) {
        super(name);
    }

    public void eat(){
        System.out.println(name+"正在吃狗粮");
    }

    @Override
    public void run() {
        System.out.println(name+"在用四条腿跑");
    }

    @Override
    public void swim() {
        System.out.println(name+"在狗刨");
    }
}

class Duck extends Animal implements IRun,ISwim{

    public Duck(String name) {
        super(name);
    }

    public void eat(){
        System.out.println(name+"正在吃虫子");
    }

    @Override
    public void run() {
        System.out.println(name+"在用两条腿走");
    }

    @Override
    public void swim() {
        System.out.println(name+"在用脚掌游");
    }
}

class Fish extends Animal implements ISwim{

    public Fish(String name) {
        super(name);
    }

    public void eat(){
        System.out.println(name+"正在吃鱼食");
    }

    @Override
    public void swim() {
        System.out.println(name+"在游泳");
    }
}

public class Demo3 {
    public static void run(IRun iRun){
        iRun.run();
    }

    public static void swim(ISwim iSwim){
        iSwim.swim();
    }

    public static void main(String[] args) {
        run(new Dog("小狗"));
        run(new Duck("小鸭子"));

        swim(new Dog("小狗"));
        swim(new Duck("小鸭子"));
        swim(new Fish("小鱼"));

        Animal animal=new Dog("11");
        animal.eat();
        Animal animal1=new Duck("22");
        animal1.eat();
        Animal animal2=new Fish("33");
        animal2.eat();
    }

}
